package twentytwentyone_3;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: Zahi
 * @Description:
 * @Date Created in 2021-03-24 10:34
 * @Modified By:
 */
public class CalPoints_682 {
    public static void main(String[] args){
        String[] ops = new String[]{"5","-2","4","C","D","9","+","+"};
        System.out.println(calPoints(ops));
    }

    public static int calPoints(String[] ops){
        List<Integer> arr = new ArrayList<>();
        for (int i = 0; i < ops.length; i++) {
            switch (ops[i]){
                case "D":
                    arr.add(arr.get(arr.size() - 1) * 2);
                    break;
                case "C":
                    arr.remove(arr.size() - 1);
                    break;
                case "+":
                    arr.add(arr.get(arr.size() - 1) + arr.get(arr.size() - 2));
                    break;
                default:
                    arr.add(Integer.parseInt(ops[i]));
                    break;
            }
        }
        int result = 0;
        for (int i = 0; i < arr.size(); i++) {
            result += arr.get(i);
        }
        return result;
    }
}
